<?php 
class home extends Controller {

var $data_view		 		= '';

var	$title					= '';
var	$tags					= '';
var	$description			= ''; 

function home()
	{
		parent::Controller();
		session_start();
		$this->load->database();
		$this->load->helper('ap_db');
		$this->load->helper('ap_object');
		$this->load->helper('ap_function');
		$this->load->helper('ap_view');
		$this->load->helper('ap_module');
		$this->load->model('home_model');
	
	}

function add_cart($nid)
{
	if(isset($_SESSION['cart'][$nid])){
		$qty = $_SESSION['cart'][$nid] + 1;
	}
	else
	{
		$qty=1;
	}
	$s = '';
	$_SESSION['cart'][$nid]=$qty;
	$_SESSION['back_link']	= base_url();
	redirect('home');
}

function delete_cart($nid)
{
	if(isset($_SESSION['cart'][$nid]))
		unset ($_SESSION['cart'][$nid]);
 
	$url = '';
	if(isset($_SESSION['back_link']))
		$url = $_SESSION['back_link'];
	else
		$url = base_url();
		
	redirect($url);
}


function index()
	{
		$this->do_process();
	}
	
function do_process() 
	{
		$this->get_data(); 		
		$this->caculate_data(); 		
		$this->do_business(); 		
		$this->destroy_data();
	}
	
private function get_data()
	{  
		// Load file ngon ngu can su dung.
		$this->load->language('ap', 'eng');
		$_SESSION['back_link']			= base_url();
	}
	
private function caculate_data()
	{
		// Get title page
		 $obj_data = get_config_byid(3);
		 foreach($obj_data as $data):
		 	$this->title	= $data['cvalue'];
		 endforeach;
		 
		 // Get keyword page
		 $obj_data = get_config_byid(2);
		 foreach($obj_data as $data):
		 	$this->tags		= $data['cvalue'];
		 endforeach;
		 
		  // Get description page
		 $obj_data = get_config_byid(4);
		 foreach($obj_data as $data):
		 	$this->description		= $data['cvalue'];
		 endforeach;
	}
	
private function do_business()
	{	

		$data['title']			= $this->title;
		$data['tags']			= $this->tags;
		$data['description']	= $this->description;
		
		$data['menu_sec']		= '';
		$data['menu_cat']		= '';
		
		$data['menu_top']		= 'home';
		
		$data['data_view'] 		= $this->data_view;
		$data['g_ishome']		= 0;
		
		$this->load->view('home',$data);	
	}
	
private function destroy_data()
	{
				
	}


}